<template>
  <div class="Home">
    <search-video @search-value="getsearchValue" v-if="searchShow" />

    <!-- 搜索展示列表 -->
    <div class="list">
      <div
        v-if="videoList.length != 0"
        v-for="(item, index) in videoList"
        :key="item.id"
        @click="getDescribe(item.id)"
      >
        <van-swipe-cell :on-close="onClose(item.id)">
          <van-card
            ref="valueitem"
            :title="item.title"
            :desc="item.pic_text"
            :thumb="item.pic_src"
            :id="item.id"
            class="item-card"
          />
          <template #right>
            <van-button square text="收藏" type="primary" class="pri-button" />
          </template>
        </van-swipe-cell>
      </div>
    </div>
  </div>
</template>

<script>
import searchVideo from "@/components/searchVideo";
export default {
  name: "Home",
  components: {
    searchVideo,
  },
  props: {
    searchShow: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      videoList: [],
    };
  },
  methods: {
    // 搜索
    getsearchValue(val) {
      if (val.data.data.length != 0) {
        this.videoList = val.data.data;
        console.log(this.videoList);
      } else {
        console.log("空");
      }
    },
    // 跳转详情
    getDescribe(val) {
      this.$router.push({ path: "/detail", query: { id: val } });
    },
    onClose(id) {
      return (clickPosition, instance) => {
        if(clickPosition == 'right'){
          console.log(id);
        }
      };
    },
  },
};
</script>


<style scoped>
.list {
  padding: 1rem 0;
}

.item-card {
  margin: 0;
  background-color: white;
}
.pri-button {
  height: 100%;
}
</style>
